﻿/** String **/
String.format = function () {

    var str = arguments[0];
    var mArr = str.match(/{\d}/ig);

    for (var j = 0; j < mArr.length; j++) {

        var idx = parseInt(mArr[j].substring(1, mArr[j].length - 1));
        if (isNaN(idx) || typeof arguments[idx + 1] == "undefined") continue;

        str = str.replace("{" + (idx + 1) + "}", arguments[idx + 1]);
    }
}

/** Object **/
Object.New = function (Class, params) {

    var instance = new Class(params);
    if (instance.inheritsFrom) {
        instance.inherits(instance.inheritsFrom, params);
    }

    return instance;
}
Object.prototype.inherits = function (parent, params) {

    var parentObject = parent;
    if (typeof parent == "function")
        parentObject = new parent(params);

    if (typeof parentObject == "object") {

        for (var attr in parentObject) {
            if (typeof this[attr] == "undefined")
                this[attr] = parentObject[attr];
        }

        this["base"] = parentObject;
    }

    parentObject = null;
}